package edu.ccut.saturn.workflow.startWorkFlowModule.code;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IParameterContext;
import edu.ccut.saturn.component.SaturnData;
import edu.ccut.saturn.operation.Operation;
import edu.ccut.saturn.workflow.common.Constants;
import edu.ccut.saturn.workflow.model.StartInfo;
import edu.ccut.saturn.workflow.model.WorkFlowInfo;

public class SetStartActivityInstance extends DefaultComponent {
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {
		SaturnData workFlowInstance = (SaturnData) parameterContext
				.getParameterValue(0);
		WorkFlowInfo workFlowInfo = (WorkFlowInfo) parameterContext
				.getParameterValue(1);
		SaturnData activityInstance = (SaturnData) parameterContext
		.getParameterValue(2);
		// 获得开始节点信息
		StartInfo startInfo = workFlowInfo.getStartInfo();
		//activityInstance.set("activity_instance_id", activity_instance_id);
		activityInstance.setString("name", startInfo.getName());
		activityInstance.setString("description", startInfo.getDescription());
		activityInstance.setString("type", startInfo.getType());
		activityInstance.set("state", Constants.ACTIVITY_STATE_FINISH);
		activityInstance.set("priority", 80);
		String limit_number = startInfo.getTimeLimit();
		// 流程的时间限制（取得开始活动中的时间限制）
		if (limit_number != null && !"".equals(limit_number)) {
			activityInstance
					.set("limit_number", Integer.parseInt(limit_number));
		} else {
			activityInstance.set("limit_number", 0);
		}
		activityInstance.setString("start_time", Operation.baseService().GetSystemTime());
		activityInstance.setString("end_time", Operation.baseService().GetSystemTime());
		activityInstance.setString("activity_id", startInfo.getId());
		activityInstance.set("process_instance_id", workFlowInstance
				.get("process_instance_id"));

	}
}